﻿<sap:ActivityDesigner x:Class="Microsoft.Samples.SqlServer.Activities.Designers.QueryFeedDesigner"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
    xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation"
    xmlns:local="clr-namespace:Microsoft.Samples.SqlServer.Activities"              
    xmlns:s="clr-namespace:System;assembly=mscorlib"  
    xmlns:sapc="clr-namespace:System.Activities.Presentation.Converters;assembly=System.Activities.Presentation" GotFocus="ActivityDesigner_GotFocus" Loaded="ActivityDesigner_Loaded">

    <sap:ActivityDesigner.Resources>
        <sapc:ArgumentToExpressionConverter x:Key="ArgumentToExpressionConverter" />
        <sapc:ModelToObjectValueConverter x:Key="ModelToObjectValueConverter" />

        <DataTemplate x:Key="ShowAsCollapsed">
            <TextBlock Foreground="Gray">
                <TextBlock.Text>
                    <MultiBinding StringFormat="Query {0}">
                        <Binding Path="ModelItem.Resource" />
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
        </DataTemplate>

        <DataTemplate x:Key="ShowAsExpanded">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition  MaxWidth="50"/>
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>

                <TextBlock Text="Uri" Grid.Row ="0" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" />

                <ComboBox MaxWidth="175" Name="urlComboBox" Grid.Row ="0" Grid.Column="1" Text="{Binding Path=ModelItem.Uri}" IsEditable="True" Margin="3,3,0,5" />

                <TextBlock Text="Resource" Grid.Row ="1" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" />
                <ComboBox DisplayMemberPath="Name"  MaxWidth="175" Margin="3,3,0,5"  Name="resourceComboBox" Grid.Row ="1" Grid.Column="1" Text="{Binding Path=ModelItem.Resource}" IsEditable="True" IsReadOnly="True" DropDownOpened="resourceComboBox_DropDownOpened" DropDownClosed="resourceComboBox_DropDownClosed">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <TextBlock Text="{Binding Path=Name}" />
                            </StackPanel>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>

                <Expander Grid.Row ="2" Grid.Column="0" Grid.ColumnSpan="3"  Height="Auto"  HorizontalAlignment="Left" Margin="0,0,0,0" Name="Filter" VerticalAlignment="Center" Width="235" IsExpanded="True">
                    <Grid Height="Auto">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>

                <TextBlock Text="Top" Grid.Row ="0" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" />

                 <sapv:ExpressionTextBox HintText="All" MaxWidth="75" MinWidth="75"
                    Grid.Row ="0" Grid.Column="1" Margin="5"
                    OwnerActivity="{Binding Path=ModelItem}"
                    Expression="{Binding Path=ModelItem.Top, Mode=TwoWay, 
                    Converter={StaticResource ArgumentToExpressionConverter}, 
                    ConverterParameter=In }"
                    ExpressionType="s:Int32"/>

                <TextBlock Text="Skip" Grid.Row ="0" Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Center" />

                <sapv:ExpressionTextBox HintText="None" 
                    Grid.Row ="0" Grid.Column="4" Margin="5" MaxWidth="75" MinWidth="75"
                    OwnerActivity="{Binding Path=ModelItem}"
                    Expression="{Binding Path=ModelItem.Skip, Mode=TwoWay, 
                    Converter={StaticResource ArgumentToExpressionConverter}, 
                    ConverterParameter=In }"
                    ExpressionType="s:Int32"/>

                <sap:WorkflowItemsPresenter
                    Grid.Row ="1" Grid.Column="0" Grid.ColumnSpan="4"                                    
                    Margin="0" MinHeight="30" AllowedItemType="{x:Type TypeName=local:Filter}" 
                    Items="{Binding Path=ModelItem.FilterActivities}">
                        <sap:WorkflowItemsPresenter.SpacerTemplate>
                            <DataTemplate>
                                    <TextBlock Margin="0,5" Background="GhostWhite" Width="200" HorizontalAlignment="Center" TextAlignment="Center" FontStyle="Italic">Drop Filter Here</TextBlock>
                            </DataTemplate>
                        </sap:WorkflowItemsPresenter.SpacerTemplate>

                        <sap:WorkflowItemsPresenter.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Vertical" />
                            </ItemsPanelTemplate>
                        </sap:WorkflowItemsPresenter.ItemsPanel>
                    </sap:WorkflowItemsPresenter>
                </Grid>
            </Expander>

            <TextBlock Margin="0,0,3,3" Text="Order By" Grid.Row ="3" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center"/>
            <ComboBox Margin="0,0,0,3" Grid.Row ="3" Grid.Column="1" Text="Select Property Names ..." Name="orderbyListBox"  IsEditable="True" IsReadOnly="True" MaxDropDownHeight="200" DropDownOpened="orderbyListBox_DropDownOpened" DropDownClosed="orderbyListBox_DropDownClosed" />

            <TextBlock Text="Select" Grid.Row ="4" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center"/>
            <ComboBox Grid.Row ="4" Grid.Column="1" Text="Select Property Names ..." Name="selectComboBox" DropDownOpened="selectCombobox_DropDownOpened" DropDownClosed="selectCombobox_DropDownClosed" IsEditable="True" IsReadOnly="True" MaxDropDownHeight="200"/>

            <TextBlock Text="Return" Grid.Row ="5" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" />
                <CheckBox Name="AsDataTable" Margin="0,3" Content="DataTable" Grid.Row ="5" Grid.Column="1" 
              FontStyle="Italic" Click="AsDataTable_Click" IsChecked="{Binding Path=ModelItem.AsDataTable}"/>
                             
            </Grid>
        </DataTemplate>

        <Style x:Key="StyleWithCollapse" TargetType="{x:Type ContentPresenter}">
            <Setter Property="ContentTemplate" 
                Value="{DynamicResource ShowAsExpanded}"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=ShowExpanded}" Value="False">
                    <Setter Property="ContentTemplate" 
                        Value="{DynamicResource ShowAsCollapsed }"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </sap:ActivityDesigner.Resources>

    <sap:ActivityDesigner.Icon>
        <DrawingBrush>
            <DrawingBrush.Drawing>
                <ImageDrawing>
                    <ImageDrawing.Rect>
                        <Rect Location="0,0"  Size="16,16" />
                    </ImageDrawing.Rect>
                    <ImageDrawing.ImageSource>

                    <BitmapImage UriSource="Items.png"/>
                    </ImageDrawing.ImageSource>
                </ImageDrawing>
            </DrawingBrush.Drawing>
        </DrawingBrush>
    </sap:ActivityDesigner.Icon>

    <Grid>
        <ContentPresenter Style="{DynamicResource StyleWithCollapse}" Content="{Binding}" />
    </Grid>

</sap:ActivityDesigner>


